package services;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import database.*;
import mapping.Categorie;

public class CategorieService {
    
   public CategorieService() {

	} 
   public List<Categorie> findAllCategories() {
		List<Categorie> listAllCategories = new ArrayList<Categorie>();
		DbManager connect = new DbManager();
		Connection conn = null;
		conn = connect.Open_ConnectDB();
		DbProcess process = new DbProcess();
		Query queryString = new Query();
		String[] table = { "Categorie" };
		String[] fields = { "id_categorie, libelle_categorie" };
		String condition = "";
		String t = queryString.Query_Select(table, fields, condition);
		ResultSet result = null;
		try {
			result = process.Get_DB(conn, t);
                        if(result!=null){
                           while (result.next()) {
				Categorie categorie = new Categorie(result.getInt(1),result.getString(2));
				listAllCategories.add(categorie);
			   } 
                        }
		} catch (Exception e) {
			System.out.println("Connexion failed");
		}
		
		connect.Close_ConnectDB(conn);
		return listAllCategories;

	} 
}


